﻿using EPE.BLL;
using EPE.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EPE.WPF
{
    /// <summary>
    /// ShopsAddForm.xaml 的交互逻辑
    /// </summary>
    public partial class ShopsAddForm : Window
    {
        public ShopsAddForm()
        {
            InitializeComponent();
        }

        CLoginUser userinfo = new CLoginUser();
        public ShopsAddForm(CLoginUser pargUserinfo)
        {
            InitializeComponent();
            userinfo = pargUserinfo;
            
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            CShops model = new CShops();


            model.shopsname = this.txtShopName.Text;
            model.buildid = Convert.ToInt32(((DataRowView)this.cmbBuild.SelectedItem).Row.ItemArray[0]);
            model.area = Convert.ToDecimal(this.txtArea.Text);
            model.located = this.txtLocated.Text;
            model.property = this.txtProperty.Text;
            model.paraid = Convert.ToInt32(((DataRowView)this.cmbPara.SelectedItem).Row.ItemArray[0]);

            Shops bll = new Shops();

            bll.Insert(model);

            MessageBox.Show("保存成功！", "系统信息", MessageBoxButton.OK, MessageBoxImage.Information);

            this.Close();
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnSelect_Click(object sender, RoutedEventArgs e)
        {
            ShopsProjectConditionForm spc = new ShopsProjectConditionForm(userinfo);


            spc.ShowDialog();

            if (spc.Model != null)
            {
                this.txtProject.Text = spc.Model.projectname.ToString();
                this.lblProjectId.Content = spc.Model.projectid.ToString();
            }

            ShopsBuild bll = new ShopsBuild();
            this.cmbBuild.ItemsSource = bll.GetAllByProjectt(userinfo.CompanyId.ToString(), this.lblProjectId.Content.ToString()).Tables[0].DefaultView;
            this.cmbBuild.SelectedValuePath = "buildid";
            this.cmbBuild.DisplayMemberPath = "buildname";

            ShopsPricePara  bllPara = new ShopsPricePara();

            this.cmbPara.ItemsSource = bllPara.GetAllByProject(this.lblProjectId.Content.ToString()).Tables[0].DefaultView;
            this.cmbPara.SelectedValuePath = "paraid";
            this.cmbPara.DisplayMemberPath = "paraname";
        }
    }
}
